﻿@{
    Layout = null;
}

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link href="~/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/css/style.css" />
    <link rel="stylesheet" href="~/assets/css/ace.min.css" />
    <link rel="stylesheet" href="~/assets/css/font-awesome.min.css" />
    <link href="~/Widget/icheck/icheck.css" rel="stylesheet" type="text/css" />
    <script src="~/layui/layui.js"></script>
    <!--[if IE 7]>
      <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
    <![endif]-->
    <!--[if lte IE 8]>
      <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="~/js/jquery-1.9.1.min.js"></script>
    <script src="~/assets/js/bootstrap.min.js"></script>
    <title>添加产品分类</title>
</head>
<body>
    <div class="type_style">
        <div class="type_title">组信息</div>
        <div class="type_content">
            <div class="Operate_btn">
                <a onclick="AddTreeNode()" class="btn  btn-warning"><i class="icon-edit align-top bigger-125"></i>新增子类型</a>
                <a onclick="Enable()" class="btn  btn-success" id="isEnableValue"></a>
                <a onclick="DelTreeNode()" class="btn  btn-danger"><i class="icon-trash   align-top bigger-125"></i>删除该类型</a>
            </div>
            <form method="post" class="form form-horizontal" id="form-user-add">
                <div class="Operate_cont clearfix">
                    <label class="form-label"><span class="c-red">*</span>分类名称：</label>
                    <div class="formControls ">
                        <input type="text" class="input-text" value="" placeholder="" id="className" name="product-category-name" nullmsg="名称不能为空">
                    </div>
                </div>
                <div class="Operate_cont clearfix">
                    <label class="form-label"><span class="c-red">*</span>排序：</label>
                    <div class="formControls ">
                        <input type="text" class="input-text" value="" placeholder="" id="sortName" name="product-category-name" nullmsg="">
                    </div>
                </div>
                <div class="Operate_cont clearfix">
                    <label class="form-label">备注：</label>
                    <div class="formControls">
                        <textarea name="" rows="" class="textarea" id="remark" placeholder="说点什么..." dragonfly="true" onKeyUp="textarealength(this,100)"></textarea>
                        <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
                    </div>
                </div>
                <div class="">
                    <div class="" style=" text-align:center">
                        <input class="btn btn-primary radius" type="submit" value="修改">
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script type="text/javascript" src="~/Widget/icheck/jquery.icheck.min.js"></script>
    <script type="text/javascript" src="~/Widget/Validform/5.3.2/Validform.min.js"></script>
    <script type="text/javascript" src="~/assets/layer/layer.js"></script>
    <script type="text/javascript" src="~/js/H-ui.js"></script>
    <script type="text/javascript" src="~/js/H-ui.admin.js"></script>
    <script type="text/javascript">

        layui.use(['table', 'jquery', 'layer'], function () {
            var table = layui.table,
                $ = layui.jquery,
                layer = layui.layer;
            var idValue = $(parent.document.getElementById("classId")).val();
             var parentValue = $(parent.document.getElementById("parent")).val();
            var nameValue = $(parent.document.getElementById("className")).val();
            var remarkValue = $(parent.document.getElementById("remark")).val();
            var sortValue = $(parent.document.getElementById("sortId")).val();
            var isEnable = $(parent.document.getElementById("isEnable")).val();
            /*赋值*/
            $("#className").val(nameValue);
            $("#remark").val(remarkValue);
            $("#sortName").val(sortValue);
            isEnable == 0 ? $("#isEnableValue").text("启用该类型") : $("#isEnableValue").text("禁用该类型");

            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });
            /*修改*/
            $("#form-user-add").Validform({
                tiptype: 2,
                beforeSubmit: function () {                                       
                    if ($("#className").val()!="") {
                        $.ajax({
                            url: "/Module/UpdateModule",
                            data: {
                                Id: idValue, Name: $("#className").val(),
                                IsEnable: $("#isEnableValue").text() == "启用该类型" ? 0 : 1,
                                SortId: $("#sortName").val(),
                                ParentId:parentValue,
                                Remark: $("#remark").val()
                            },
                            type: "post",
                            success: function (data) {
                                if (data.Success) {
                                    window.parent.location.reload();
                                }
                            }
                        });
                    } else {
                        layer.msg("名称不能为空");
                        return false;
                    }
                }
            });
            //新增
            AddTreeNode = function () {
                if ($("#className").val() != "") {
                    $.ajax({
                        url: "/Module/AddModule",
                        data: { ParentId: idValue, Name: $("#className").val(), IsEnable: 1, SortId: $("#sortName").val(), Remark: $("#remark").val() },
                        type: "post",
                        success: function (data) {
                            if (data.Success) {
                                window.parent.location.reload();

                            }
                        }
                    });
                } else {
                    layer.alert("名称不能为空");
                }
            }
            /*修改状态*/
            Enable = function () {
                $.ajax({
                    url: "/Module/UpdateModuleStatu",
                    data: { Id: idValue, IsEnable: $("#isEnableValue").text() == "禁用该类型" ? 0 : 1 },
                    type: "post",
                    success: function (data) {
                        if (data.Success) {
                            window.parent.location.reload();
                        }
                    }
                });
            }

            //删除
            DelTreeNode = function () {
                if ($("#className").val() != "") {
                    layer.confirm("确定删除吗?", function () {
                        $.ajax({
                            url: "/Module/DelModule",
                            data: { Id: idValue },
                            type: "post",
                            success: function (data) {
                                if (data.Success) {
                                    window.parent.location.reload();
                                }
                            }
                        });
                    });
                } else {
                    layer.alert("名称不能为空");
                }
            }
        });
    </script>
</body>
</html>
